<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> - 登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
	<link href="__ROOT__/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
	<link href="__ROOT__/Public/Admin/css/style.css" rel="stylesheet">
	<link href="__ROOT__/Public/Admin/css/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
	<style>
		span.help-block{color:red;}
		.tips{color:red;}
	</style>
</head>

<body>
	<div class="logo"></div>
	<div class="signin">
		<div class="signinpanel">
	        <div class="row">
	            <div class="col-sm-12">
	                <form class="js-ajax-forms" method="post" action="{:U('Admin/Public/login')}">
	                    <h4 class="no-margins">系统登录&nbsp;&nbsp;<span class="no-margins-border"></span>&nbsp;&nbsp;System Login</h4>
						<div>
							<span class="input-border"></span>
							<input name="UserName" id="UserName" type="text" class="form-control uname" placeholder="用户名" />
						</div>
						<div>
							<span class="input-border"></span>
							<input name="Password" id="Password" type="password" class="form-control pword m-b" placeholder="密码" />
						</div>
						<div class="tips"></div>
								<a href="{:U('Admin/Public/findPassword')}" class="forget-password">忘记密码了？</a>
	                    <a href="{:U('Admin/Public/register')}" class="register">注册</a>
	                    <button type="submit" class="btn btn-success btn-block">登录</button>
	                </form>
	            </div>
	        </div>
	    </div>
	</div>
	<div class="signup-footer">
        <div class="pull-left">
           <span class="copy-dot"></span> copyright &copy; 江苏科健教育软件有限公司 <span class="copy-dot"></span>
        </div>
    </div>
	<script src="__ROOT__/Public/Admin/js/jquery.min.js?v=2.1.4"></script>
	<script src="__ROOT__/Public/Admin/js/bootstrap.min.js?v=3.3.6"></script>
	<script type="text/javascript" src="__ROOT__/Public/Admin/js/ajaxForm.js"></script>
	<script src="__ROOT__/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
	<script src="__ROOT__/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
	<script>
		$(document).ready(function () {
			$.validator.setDefaults({
				highlight: function (element) {
					$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
				},
				success: function (element) {
					element.closest('.form-group').removeClass('has-error').addClass('has-success');
				},
				errorElement: "span",
				errorPlacement: function (error, element) {
					if (element.is(":radio") || element.is(":checkbox")) {
						error.appendTo(element.parent().parent().parent());
					} else {
						error.appendTo(element.parent());
					}
				},
				errorClass: "help-block m-b-none",
				validClass: "help-block m-b-none "
			});

			$.validator.addMethod("isPhone", function (value, element) {
				var phone = /^1[34578]\d{9}$/;
				return phone.test(value);
			}, "请输入正确的手机号码");

			var icon = "<i class='fa fa-times-circle'></i> ";
			var form = $('form.js-ajax-forms');
			var formloading = false;
			//表单验证开始
			form.validate({
				//验证规则
				rules: {
					UserName: {
						required: true,
					},
					Password: {
						required: true
					}
				},
				//验证未通过提示消息
				messages: {
					UserName: {
						required: icon + "请输入用户名"
					},
					Password: {
						required: icon + "请输入密码"
					}
				},
				//验证通过，提交表单
				submitHandler: function (forms) {
					if (formloading)
						return;
					$(forms).ajaxSubmit({
						url: form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
						dataType: 'json',
						beforeSubmit: function (arr, $form, options) {
							formloading = true;
						},
						success: function (data, statusText, xhr, $form) {
							console.log(JSON.stringify(data));
							formloading = false;
							if (data.status) {
								if(document.referrer){
									location.href = document.referrer;
								}else{
									location.href = '/';
								}
							} else {
								$('.tips').html(data.info);
								$('.tips').show();
							}
						}
					});
				}
			});

			$('input').focus(function(){
				$('.tips').hide();
				$('.tips').html('');
			});
		});
	</script>
</body>
</html>
